package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.CleanModel;
import com.jiayang.hhotel.bean.Constant;
import com.jiayang.hhotel.bean.RoundsModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.RoundsHisActivity;
import com.jiayang.hhotel.util.ToastUtil;


import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/5/18 0018.
 * 查房历史逻辑类
 */

public class RoundsHisPresenter extends XPresent<RoundsHisActivity> {

    /**
     * 获取查房历史列表
     * @param mpLanguage 语言
     * @param page 页数
     */
    public void asyncRoundsData(int mpLanguage, int mpOperation, int page){
        Api.getHomeSer().getRoundsList(Constant.PHONE,mpLanguage,mpOperation,1,page)
                .compose(XApi.<RoundsModel>getApiTransformer())
                .compose(XApi.<RoundsModel>getScheduler())
                .compose(getV().<RoundsModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<RoundsModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().sealPic(error.getType());
                    }

                    @Override
                    public void onNext(RoundsModel Model) {
                        switch (Model.getState()){
                            case 9://请求成功
                                getV().setRoundsAdapter(Model.getPCheckRoomListDtos());
                                break;
                            case -1://失败
                                getV().sealPic(-1);
                                break;
                            case 1002://没有数据
                                getV().sealPic(1002);
                                break;
                        }
                    }
                });
    }

    /**
     * 获取清洁历史列表
     * @param mpLanguage 语言
     * @param mpOperation 1表历史
     * @param page 页数
     */
    public void asyncCleanData(int mpLanguage,int mpOperation,int page){
        Api.getHomeSer().getCleanList(Constant.PHONE,mpLanguage,mpOperation,page,6)
                .compose(XApi.<CleanModel>getApiTransformer())
                .compose(XApi.<CleanModel>getScheduler())
                .compose(getV().<CleanModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<CleanModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        getV().sealPic(error.getType());
                    }

                    @Override
                    public void onNext(CleanModel Model) {
                        switch (Model.getState()){
                            case 9://请求成功
                                getV().setCleanAdapter(Model.getPCleanRoomListDtos());
                                break;
                            case -1://失败
                                getV().sealPic(-1);
                                break;
                            case 1002://没有数据
                                getV().sealPic(1002);
                                break;
                        }
                    }
                });
    }
}
